package vues;

import javax.swing.JButton;
import javax.swing.JPanel;

import logique.administration.Administration;

/**
 * 
 * @author Matthieu
 *
 */
public class PanelReseau extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5084717631782511741L;
	
	// ATTRIBUTES //
	public final InterfacePrincipale gps;
	private JButton boutonValider;
	private JButton boutonRecharger;
	private Administration miseAJour;
	private GraphEditorDemo graphe;
	
	public PanelReseau(InterfacePrincipale gps) {
		// Enregistrement de la reference sur la fenetre principale
		this.gps = gps;
		this.boutonValider = new JButton();
		this.boutonRecharger = new JButton();
		miseAJour = gps.controleur.getAdministration();
		
		// Initialisation du panel
		boutonValider.setText("Valider");
		boutonValider.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				validerEdition();
			}
		});

		this.add(boutonValider, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 320, -1, -1));
		
		boutonRecharger.setText("Recharger");
		boutonRecharger.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				sourisRechargerReseau();
			}

		});

		this.add(boutonRecharger, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 320, -1, -1));

		
		// On affiche le graphe 
		graphe = new GraphEditorDemo(gps.controleur);
        this.add(graphe.vv, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 100, 200, 200));
		
	}

	protected void validerEdition() {
		gps.controleur.getAdministration().valideModifications();
	}

	protected void sourisRechargerReseau() {
		// On recharge le graphe avec le r�seau courant
		this.remove(graphe.vv);
		graphe = new GraphEditorDemo(gps.controleur);
        this.add(graphe.vv);
        this.gps.repaint();
	}

}
